package com.zengqingfa.springboot.validation.demo.util;

import lombok.Data;
import lombok.experimental.Delegate;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

/**
 * 可被校验的List
 *
 * @param <E> 元素类型
 * @author Deolin
 */
@Data
 public class ValidableList<E> implements List<E> {
 
    @Valid
    @Delegate
    private List<E> list;
     
    public ValidableList() {
        this.list = new ArrayList<>();
    }
    
    public ValidableList(List<E> list) {
        this.list = list;
    }
    
    public List<E> getList() {
        return list;
    }

    public void setList(List<E> list) {
        this.list = list;
    }

    // 其他的Override方法省略。它们与size()和isEmpty()类似，直接调用private List list处理。 

    @Override
    public String toString() {
        return "ValidableList{" +
                "list=" + list +
                '}';
    }
}
